/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ez2find.backing;

import com.ez2find.manager.ForumManagerLocal;
import com.ez2find.manager.TopicManagerLocal;
import java.util.List;
import com.ez2find.model.Forum;
import com.ez2find.util.SessionContext;
import javax.ejb.EJB;
import com.ez2find.model.Topic;
import java.util.Date;
import org.richfaces.component.UITree;
import org.richfaces.component.state.TreeStateAdvisor;

/**
 *
 * @author org.@le
 */

public class ForumsRequest implements TreeStateAdvisor {
    
    @EJB
    ForumManagerLocal ejbForums;
    @EJB
    TopicManagerLocal ejbTopics;
    
    /** Creates a new instance of ForumsRequest */
    public ForumsRequest() {
    }
    
    public Date getCurrentDate(){
        Date fecha= new Date();
        return fecha;
    }
    
    public List<Forum> getForums(){
        return ejbForums.listAll();
    }
    
    public List<Topic> getTopics(){
        ForumsSession fBean = (ForumsSession) SessionContext.getAttribute("ForumsSession");
        
        return ejbTopics.invertedTopics(fBean.getCurrentForum());
    }

    public Boolean adviseNodeOpened(UITree arg0) {
        return true;
    }

    public Boolean adviseNodeSelected(UITree arg0) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    public String nTopic(){
        SessionBean sessionBean = (SessionBean) SessionContext.getAttribute("sessionBean");
        
        if ((sessionBean.getEjbSession().getOwner()!=null) && (!sessionBean.getEjbSession().getOwner().getHandles().isEmpty())){
            return "ntopic";
        }else{
            return "error"; 
        }
    }
    public String nMessage(){
        SessionBean sessionBean = (SessionBean) SessionContext.getAttribute("sessionBean");
        
        if ((sessionBean.getEjbSession().getOwner()!=null) && (!sessionBean.getEjbSession().getOwner().getHandles().isEmpty())){
            return "nMessage";
        }else{
            return "error"; 
        }
    }
    public String cReply(){
        SessionBean sessionBean = (SessionBean) SessionContext.getAttribute("sessionBean");
        
        if ((sessionBean.getEjbSession().getOwner()!=null) && (!sessionBean.getEjbSession().getOwner().getHandles().isEmpty())){
            return "cReply";
        }else{
            return "error"; 
        }
    }
    
    public String sEmail(){
        SessionBean sessionBean = (SessionBean) SessionContext.getAttribute("sessionBean");
        
        if ((sessionBean.getEjbSession().getOwner()!=null) && (!sessionBean.getEjbSession().getOwner().getHandles().isEmpty())){
            return "sEmail";
        }else{
            return "error"; 
        }
    }
    
     public String flag(){
        SessionBean sessionBean = (SessionBean) SessionContext.getAttribute("sessionBean");
        
        if ((sessionBean.getEjbSession().getOwner()!=null) && (!sessionBean.getEjbSession().getOwner().getHandles().isEmpty())){
            return "flag";
        }else{
            return "error"; 
        }
    }
     
     public boolean isTooManyHandles(){
        SessionBean sessionBean = (SessionBean) SessionContext.getAttribute("sessionBean");
        if (sessionBean.getTooManyHandles()) return true;
        else return false;
     }
    
}
